
// Copyright (C) Recursion Company. All rights reserved.

#ifndef __VOL_MFC_UI_IE_BROWSER_H__
#define __VOL_MFC_UI_IE_BROWSER_H__

#include <afxhtml.h>

class IIEBrowserEventListener : public IBaseEventListener
{
public:
    virtual void OnProgressChange (INT nProgress) = 0;
    virtual void OnCommandStateChange (INT nCommand, BOOL blEnabled) = 0;
    virtual void OnDownloadBegin () = 0;
    virtual void OnDocumentComplete (CVolString& strURL) = 0;
    virtual void OnDownloadComplete () = 0;
    virtual void OnTitleChange (CVolString& strTitle) = 0;
    virtual BOOL OnNewWindow (CVolString& strURL) = 0;
    virtual BOOL OnBeforeNavigate (CVolString& strURL) = 0;
    virtual void OnStatusTextChange (CVolString& strStatusText) = 0;
    virtual void OnNavigateComplete (CVolString& strURL) = 0;
};

#define _VOL_OLE_TRUE  (-1)
#define _VOL_OLE_FALSE  0

class CVWnd_IEBrowser : public CWnd
{
    DECLARE_VOL_NATIVE_WND_CLASS (CVWnd_IEBrowser, CWnd, IIEBrowserEventListener, FALSE)

public: 
    ~CVWnd_IEBrowser ();

public:
    inline_ IWebBrowser2* GetBrowser() { return m_pBrowserApp; }
    CVolComObject& GetBrowserIDispathObject (CVolComObject& objCom);
    CVolComObject& GetDocumentIDispathObject (CVolComObject& objCom);
                
    CVolString GetType() const;
    BOOL GetBusy() const;
    READYSTATE GetReadyState() const;
    CVolString GetLocationName() const;
    long GetLeft() const;
    long GetTop() const;
    long GetHeight() const;
    BOOL GetVisible() const;
    BOOL GetOffline() const;
    BOOL GetSilent() const;
    CVolString GetLocationURL() const;

    inline_ void SetLeft(long nNewValue) { if (m_pBrowserApp != NULL) m_pBrowserApp->put_Left(nNewValue); }
    inline_ void SetTop(long nNewValue) { if (m_pBrowserApp != NULL) m_pBrowserApp->put_Top(nNewValue); }
    inline_ void SetHeight(long nNewValue) { if (m_pBrowserApp != NULL) m_pBrowserApp->put_Height(nNewValue); }
    inline_ void SetVisible(BOOL fNewValue) { if (m_pBrowserApp != NULL) m_pBrowserApp->put_Visible((short) (fNewValue ? _VOL_OLE_TRUE : _VOL_OLE_FALSE)); }
    inline_ void SetOffline(BOOL fNewValue) { if (m_pBrowserApp != NULL) m_pBrowserApp->put_Offline((short) (fNewValue ? _VOL_OLE_TRUE : _VOL_OLE_FALSE)); }
    inline_ void SetSilent(BOOL fNewValue) { if (m_pBrowserApp != NULL) m_pBrowserApp->put_Silent((short) (fNewValue ? _VOL_OLE_TRUE : _VOL_OLE_FALSE)); }

    inline_ void GoBack() { if (m_pBrowserApp != NULL) m_pBrowserApp->GoBack(); }
    inline_ void GoForward() { if (m_pBrowserApp != NULL) m_pBrowserApp->GoForward(); }
    inline_ void GoHome() { if (m_pBrowserApp != NULL) m_pBrowserApp->GoHome(); }
    inline_ void GoSearch() { if (m_pBrowserApp != NULL) m_pBrowserApp->GoSearch(); }
    inline_ void Refresh() { if (m_pBrowserApp != NULL) m_pBrowserApp->Refresh(); }
    inline_ void Stop() { if (m_pBrowserApp != NULL) m_pBrowserApp->Stop(); }

    void RunCmd (OLECMDID cmdid);
    void ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt, VARIANT* pvaIn, VARIANT* pvaOut);
    HRESULT Navigate (LPCTSTR URL, DWORD dwFlags = 0, LPCTSTR lpszTargetFrameName = NULL,
            LPCTSTR lpszHeaders = NULL, LPVOID lpvPostData = NULL, DWORD dwPostDataLen = 0);
    HRESULT NavigateChm(LPCTSTR szChmFileName, LPCTSTR URL, LPCTSTR lpszTargetFrameName = NULL);

    void PropSetFontSize (INT nFontSize);
    void PropSetOffline (BOOL blOffline);
    void PropSetSilent (BOOL blSilent);
    void PropSetURL (const TCHAR* szURL);

    inline_ INT PropGetFontSuze () const  { return m_nFontSize; } 
    BOOL PropGetOffline () const;
    BOOL PropGetSilent () const;
    CVolString PropGetURL () const;

    // Events
	void OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers, VARIANT_BOOL* Cancel);
    void OnDownloadBegin();
    void OnProgressChange(long nProgress, long nProgressMax);
    void OnDownloadComplete();
    void OnDocumentComplete(LPDISPATCH pDisp, VARIANT* URL);
    void OnStatusTextChange(LPCTSTR lpszText);
    void OnTitleChange(LPCTSTR lpszText);
    void OnCommandStateChange(long nCommand, BOOL fEnable);
    void OnNavigateComplete2(LPDISPATCH pDisp, VARIANT* URL);
    void OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel);

public:
    DECLARE_EVENTSINK_MAP ()

    //{{AFX_MSG(CVWnd_IEBrowser)
	afx_msg void OnSetFocus(CWnd* pOldWnd);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnDestroy();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()

protected:
	CWnd m_wndBrowser;
    IWebBrowser2* m_pBrowserApp;

	INT m_nFontSize;
    BOOL m_blOffline;
    BOOL m_blSilent;
	CVolString m_strURL;
};

#endif
